package org.example.redpacket.handler;

import org.springframework.http.HttpStatus;

import java.util.HashMap;

/**
 * HTTP 统一出参
 *
 * @author: hero生仔
 */
public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    private static final Integer SUCCESS = HttpStatus.OK.value();

    private static final Integer FAIL = HttpStatus.INTERNAL_SERVER_ERROR.value();

    public static R ok(String msg) {
        R r = new R();
        r.put("code", SUCCESS);
        r.put("message", msg);
        return r;
    }

    public static R ok() {
        R r = new R();
        r.put("code", SUCCESS);
        r.put("message", "");
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.put("code", FAIL);
        r.put("message", msg);
        r.put("data", "");
        return r;
    }

    public R setData(Object data) {
        put("data", data);
        return this;
    }
}
